Skip to content

refactor: Port TryCastExpr proto serialization hooks#22550

Open
chakkk309 wants to merge 1 commit into
apache:mainfrom
chakkk309:fix-try-cast-proto-hooks
Open

refactor: Port TryCastExpr proto serialization hooks#22550
chakkk309 wants to merge 1 commit into
apache:mainfrom
chakkk309:fix-try-cast-proto-hooks

Conversation

@chakkk309
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

This is part of #22418, which migrates built-in PhysicalExpr implementations away from the central protobuf serialization / deserialization chains.

TryCastExpr can now own its protobuf serialization through PhysicalExpr::try_to_proto and its deserialization through TryCastExpr::try_from_proto, matching the pattern used by previously migrated physical expressions.

What changes are included in this PR?

  • Adds PhysicalExpr::try_to_proto support for TryCastExpr.
  • Adds TryCastExpr::try_from_proto.
  • Wires TryCastExpr deserialization in from_proto.rs through the new hook.
  • Removes the old TryCastExpr serialization branch from the central to_proto.rs downcast chain.
  • Adds direct proto hook tests for successful encoding / decoding and invalid protobuf inputs.

Are these changes tested?

Yes.

I ran:

cargo fmt --all --check
git diff --check
cargo test -p datafusion-physical-expr --features proto try_cast
cargo test -p datafusion-proto --test proto_integration
cargo clippy -p datafusion-physical-expr --features proto --tests -- -D warnings
cargo clippy -p datafusion-proto --tests -- -D warnings

Are there any user-facing changes?

No. This is an internal protobuf serialization refactor for TryCastExpr; the wire format remains unchanged.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates proto Related to proto crate labels May 27, 2026
@chakkk309 chakkk309 force-pushed the fix-try-cast-proto-hooks branch from 2920ae1 to fe2fcd0 Compare May 28, 2026 02:38
Copy link
Copy Markdown
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit!

Comment on lines +220 to +233
#[cfg(feature = "proto")]
use datafusion_common::DataFusionError;
use datafusion_physical_expr_common::physical_expr::fmt_sql;
#[cfg(feature = "proto")]
use datafusion_physical_expr_common::physical_expr::proto_decode::PhysicalExprDecodeCtx;
#[cfg(feature = "proto")]
use datafusion_physical_expr_common::physical_expr::proto_encode::PhysicalExprEncodeCtx;
#[cfg(feature = "proto")]
use datafusion_proto_models::protobuf::{self, physical_expr_node};

#[cfg(feature = "proto")]
use crate::proto_test_util::{
StubDecoder, StubEncoder, UnreachableDecoder, column_node,
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be easier to just make a new test module:

#[cfg(all(test, feature = "proto"))]
mod proto_tests {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks! Already changed.

@adriangb
Copy link
Copy Markdown
Contributor

#22596 adds an expect_expr_variant! macro and a require_proto_field helper that together collapse the outer match and any non-expression "missing required field" ok_or_else to one line each. Could you rebase onto it and adopt them before final review?

@chakkk309 chakkk309 force-pushed the fix-try-cast-proto-hooks branch from fe2fcd0 to 351c2b1 Compare May 29, 2026 05:22
@adriangb adriangb added this pull request to the merge queue May 29, 2026
@adriangb
Copy link
Copy Markdown
Contributor

thanks!

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch May 29, 2026
@adriangb
Copy link
Copy Markdown
Contributor

@chakkk309 can you please resolve conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates proto Related to proto crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port TryCastExpr to use try_to_proto / try_from_proto

2 participants